<%--
  Created by bothin
  At 2019/12/19 15:17
  Description: 
--%>
<%@ page import="com.bothin.experiment4.enums.ProductFormStatusEnum" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <%@include file="../../component/head_link_css_js.jsp"%>

    <style>
        .layui-form-item .layui-input-inline{
            width: 280px;
        }
    </style>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <!-- 头部区域 -->
    <%@include file="../../component/nav_header.jsp"%>
    <!-- 侧边菜单 -->
    <jsp:include page="../../component/nav_side_menu.jsp">
        <jsp:param name="nav" value="3#${index}" />
    </jsp:include>

    <!-- 内容主体区域 -->
    <div class="layui-body" id="LAY_app_body" style="top: 50px;">
        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-card-header layuiadmin-card-header-auto">
                    <div style="padding-bottom: 10px;">
                        <div class="layui-form-item">
                            <form action="${pageContext.request.contextPath}/stockman/manage/in/list/unhandle">
                                <div class="layui-inline">
                                    <div class="layui-input-block" style="width: 300px;">
                                        <input type="text" name="keyword" placeholder="按进货编号查找" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <button class="layui-btn layuiadmin-btn-admin" type="submit">
                                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                    </button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <div class="layui-card-body" style="padding-bottom: 50px;">
                    <table class="layui-table">
                        <colgroup>
                            <col width="180">
                            <col><col><col>
                            <col><col>
                            <col width="90">
                            <col width="${index==1?"140":"90"}">
                        </colgroup>
                        <thead>
                        <tr>
                            <th>进货编号</th>
                            <th>商品名称</th>
                            <th>商品图片</th>
                            <th>商品库存</th>
                            <c:if test="${index==1}"><th>目前缺货数量</th></c:if>
                            <c:if test="${index==2}"><th>进货数量</th></c:if>
                            <th>物流编号</th>
                            <th>物流信息</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:set var="stockman_page" scope="session" value="${pageInfo.pageNum}"/>
                        <c:if test="${pageInfo.size==0}">
                            <tr>
                                <td colspan="8">暂时无数据显示</td>
                            </tr>
                        </c:if>
                        <c:forEach items="${pageInfo.list}" var="item">
                            <tr>
                                <td>${item.formId}</td>
                                <td>${item.productName}</td>
                                <td><img src="${item.productIcon}" alt="商品图片" style="width: 60px;height: 60px;"></td>
                                <td>${item.productStock}</td>
                                <td>${item.productQuantity<0?-item.productQuantity:item.productQuantity}</td>
                                <td>
                                    <c:if test="${item.logistInfo==null}">
                                        尚未采购
                                    </c:if>
                                    <c:if test="${item.logistInfo!=null}">
                                        <span class="logist_detail" data-fid="${item.logistInfo.id}" style="cursor: pointer;">${item.logistInfo.id}</span>
                                    </c:if>
                                </td>
                                <td>
                                    <c:if test="${item.getProductFormStatusEnum().equals(ProductFormStatusEnum.UNFINISHED)}">
                                        <button class="layui-btn layui-btn-primary layui-btn-xs">${ProductFormStatusEnum.UNFINISHED.message}</button>
                                    </c:if>
                                    <c:if test="${item.getProductFormStatusEnum().equals(ProductFormStatusEnum.TRANSIT)}">
                                        <button class="layui-btn layui-btn-warm layui-btn-xs">${ProductFormStatusEnum.TRANSIT.message}</button>
                                    </c:if>
                                    <c:if test="${item.getProductFormStatusEnum().equals(ProductFormStatusEnum.FINISH)}">
                                        <button class="layui-btn layui-btn-normal layui-btn-xs">${ProductFormStatusEnum.FINISH.message}</button>
                                    </c:if>
                                </td>
                                <td>
                                    <c:if test="${item.getProductFormStatusEnum().equals(ProductFormStatusEnum.UNFINISHED)}">
                                        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm employee_add " data-eid="${item.formId}">进货</button>
                                        <button  class="layui-btn layui-btn-danger layui-btn-sm form_delete" data-eid="${item.formId}">删除</button>
                                    </c:if>
                                    <c:if test="${item.getProductFormStatusEnum().equals(ProductFormStatusEnum.FINISH)}">
                                        <c:if test="${item.productQuantity<=0}">
                                            已加库存
                                        </c:if>
                                        <c:if test="${item.productQuantity>0}">
                                            <button type="button" class="layui-btn layui-btn-normal layui-btn-sm add_finish " data-eid="${item.formId}">已收货</button>
                                        </c:if>
                                    </c:if>
                                </td>
                            </tr>
                        </c:forEach>

                        </tbody>
                    </table>
                    <div class="layui-btn-group" style="position: absolute;right: 14px;margin-top: 10px;">
                        <a type="button" class="layui-btn layui-btn-primary layui-btn-sm ${pageInfo.hasPreviousPage!=true?"layui-btn-disabled":''}"
                           href="${pageContext.request.contextPath}/stockman/manage/in/list/${index==1?"unhandle":"handled"}?page=${pageInfo.pageNum-1}${key}"
                        >
                            <i class="layui-icon">&#xe603;</i>
                        </a>
                        <c:forEach var="i" begin="1" end="${pageInfo.pages}">
                            <a type="button" class="layui-btn layui-btn-${pageInfo.pageNum==i?"normal":"primary"} layui-btn-sm"
                               href="${pageContext.request.contextPath}/stockman/manage/in/list/${index==1?"unhandle":"handled"}?page=${i}${key}">${i}</a>
                        </c:forEach>
                        <a type="button" class="layui-btn layui-btn-primary layui-btn-sm ${pageInfo.hasNextPage!=true?"layui-btn-disabled":''}"
                           href="${pageContext.request.contextPath}/stockman/manage/in/list/${index==1?"unhandle":"handled"}?page=${pageInfo.pageNum+1}${key}"
                        >
                            <i class="layui-icon">&#xe602;</i>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="hide_form_content" style="display: none">
    <div class="layui-form-item" style="margin-top: 20px;margin-left: 10px;">
        <label class="layui-form-label">进货数量 *</label>
        <div class="layui-inline">
            <input min="1" type="number" id="productQuantity" name="productQuantity" placeholder="请填写进货数量" class="layui-input">
        </div>
    </div>
</div>
<div id="hide_form_content3" style="display: none"></div>
</body>
</html>
<script>
    layui.config({
        base: '${pageContext.request.contextPath}/resources/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table','sample','useradmin','layer','form'], function(){

        var $ = layui.$
            ,form = layui.form
            ,table = layui.table,layer=layui.layer;

        $('.employee_add').on('click', function(){
            var formId = $(this).data('eid');

            //重置input框
            $("#productQuantity").val("");

            layer.open({
                type: 1
                ,title: '定单发货'
                ,content: $("#hide_form_content")
                ,area: '360px'
                ,offset: '100px'
                ,shadeClose:true
                ,btn: ['发货']
                ,yes: function(index, layero){
                    var productQuantity = $("#productQuantity").val();
                    if (productQuantity==undefined||productQuantity==""){
                        alert("进货数量不能为空！！");
                        return;
                    }
                    $.ajax({
                        type: 'GET',
                        url: '${pageContext.request.contextPath}/stockman/manage/in/form/change',
                        data: {formId:formId,productQuantity:productQuantity},
                        contentType: 'text/json',
                        dataType: 'json',
                        success: function (data) {
                            console.log(data)
                            if (data.code == 0){
                                //layer.close(index); //关闭弹层
                                layer.msg(data.msg , {
                                    offset: '100px',
                                    time: 2500
                                });
                                setTimeout('location.reload();',600);
                            }else {
                                layer.msg(data.msg , {
                                    offset: '100px',
                                    time: 2000
                                });
                            }
                        }
                    });
                    layer.close(index); //关闭弹层
                }
            });
        });

        $('.add_finish').on('click', function(){
            var formId = $(this).data('eid');

            layer.confirm('商品已收到? 修改商品库存？', {icon: 3, title:'修改商品库存',offset: '100px'}, function(index){
                //do something
                //AJAX
                $.ajax({
                    type: 'GET',
                    url: '${pageContext.request.contextPath}/stockman/manage/in/product/add',
                    data: {formId:formId},
                    contentType: 'text/json',
                    dataType: 'json',
                    success: function (data) {
                        layer.msg(data.msg, {
                            offset: '100px',
                            time: 2500
                        });
                        setTimeout('location.reload();', 600);
                    }
                });
                layer.close(index);
            });
        });

        $('.form_delete').on('click', function(){
            var formId = $(this).data('eid');

            layer.confirm('确定要删除这条进货提醒? ', {icon: 3, title:'删除提醒',offset: '100px'}, function(index){
                //do something
                //AJAX
                $.ajax({
                    type: 'GET',
                    url: '${pageContext.request.contextPath}/stockman/manage/in/notice/delete',
                    data: {formId:formId},
                    contentType: 'text/json',
                    dataType: 'json',
                    success: function (data) {
                        layer.msg(data.msg, {
                            offset: '100px',
                            time: 2500
                        });
                        setTimeout('location.reload();', 600);
                    }
                });
                layer.close(index);
            });
        });

        $('.logist_detail').on('click', function(){
            var fid = $(this).data('fid');
            console.log(fid)
            var url = "${pageContext.request.contextPath}/logist/to/detail";
            if (fid!=undefined)
                url += "?logistId="+fid;
            $("#hide_form_content3").load(url);

            layer.open({
                type: 1
                ,title: '物流详情'
                ,content: $("#hide_form_content3")
                ,area: '560px'
                ,offset: '100px'
                ,shadeClose:true
            });
        });
    });
</script>
